#ifndef G3_3DD_LUA_H
#define G3_3DD_LUA_H

#include "spline.h"

#include "color.h"
#include "math/m_vector.h"
#include "lua_handler.h"
#include "file/f_stream.h"
#include "file/f_absfs.h"
#include "frame.h"

//==============================================================================
// Loads all the necessary bindings for Lua configuration scripts
//==============================================================================
int tolua_3ddcs_open (lua_State *LuaState);

//==============================================================================
// Configuration Script variables
//==============================================================================
extern G3::FRAME frame;
// Spline color
extern G3::COL3F G3CS_Fg_Color;
// Spline smoothness (default is 10)
extern int G3CS_Subdivisions;
// Should we display the grid with axis arrows? (Debug only)
extern bool G3CS_Display_Grid;
// Should we display tiny axis? (Helps for orientation)
extern bool G3CS_DisplayAxis;
// Viewport background color
extern G3::COL3F G3CS_Bg_Color;
// Resolution
extern G3::VEC2I G3CS_Resolution;
// Color Depth (Fullscreen)
extern int G3CS_ColDepth;
// Start fullscreen?
extern bool G3CS_FullScreen;
// Spline width (default is 0.01)
extern float G3CS_SplineWidth;
// Spline detail (default is 4)
extern float G3CS_SplineDetail;
// The sensitivity of planar X, Y movement
extern float G3CS_3DM_PlanarSensitivity;
// The sensitivity of rotation around the Base of the Axis
extern float G3CS_3DM_RotateSensitivity;
// The sennsitivity of rotation around the Base of the Axis with Nunchuk
extern float G3CS_WII_NunchukRotateSensitivity;
// The level of noise eliminated from the Nunchuk
extern float G3CS_WII_NunchukNoiseLevel;
// The sensitivity of Z movement
extern float G3CS_3DM_DepthSensitivity;
// Should we use the normal mouse instead of a Wiimote?
extern bool G3CS_3DM_UseNormalMouse;
// Wiimote depth sensitivity
extern float G3CS_WII_DepthSensitivity;
// Depth low-pass filter noise reduction percentage
extern float G3CS_WII_DepthNoiseReduction;
// Depth low-pass filter noise reduction iterations
extern int G3CS_WII_NoiseFilterIterations;
// Minimum depth
extern float G3CS_WII_MinDepth;
// Global Luascript variable for Wiimote IR sensitivity
extern int G3CS_WII_IRSensitivity;
// Zoom sensitivity
extern float G3CS_WII_ZoomSensitivity;
// Light position
extern G3::VEC3F G3CS_Lightpos;
// Camera start position
extern G3::VEC3F G3CS_Camerapos;
// Profiling enabled / disabled
extern bool G3CS_Profiling;

//==============================================================================
// Loads a Lua configuration script from a stream or a file
//==============================================================================
bool LoadConfig (G3::STREAM *aStream);
bool LoadConfig (const char *aFilename);

//==============================================================================
// Sets background color
//==============================================================================
static void G3CS_SetBgColor (float aR, float aG, float aB) {
    G3CS_Bg_Color.r = aR;
    G3CS_Bg_Color.g = aG;
    G3CS_Bg_Color.b = aB;
}

//==============================================================================
// Sets foreground color
//==============================================================================
static void G3CS_SetFgColor (float aR, float aG, float aB) {
    G3CS_Fg_Color.r = aR;
    G3CS_Fg_Color.g = aG;
    G3CS_Fg_Color.b = aB;
}

//==============================================================================
// Sets the resolution
//==============================================================================
static void G3CS_SetResolution (int aWidth, int aHeight) {
    if (aWidth >= 1 && aHeight >= 1) {
        G3CS_Resolution.x = aWidth;
        G3CS_Resolution.y = aHeight;
    }
}

//==============================================================================
// Loads a spline on startup
//==============================================================================
/*
static void G3CS_LoadSpline (std::string aFilename) {
    Spline.Load (aFilename);
}*/

//==============================================================================
// Resets the camera to a position
//==============================================================================
static void G3CS_ResetCamera (float aX, float aY, float aZ) {
    G3CS_Camerapos.x = aX;
    G3CS_Camerapos.y = aY;
    G3CS_Camerapos.z = aZ;
}

static void G3CS_SetLightPos (float aX, float aY, float aZ) {
    G3CS_Lightpos.x = aX;
    G3CS_Lightpos.y = aY;
    G3CS_Lightpos.z = aZ;
}

#endif

